package com.zg.scf.web;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zg.common.core.R;
import com.zg.common.core.dao.scf.CompanyDao;
import com.zg.common.core.dao.scf.entity.Company;
import com.zg.scf.domain.convert.CompanyConvert;
import com.zg.scf.domain.req.company.CompanyAddReq;
import com.zg.scf.domain.req.company.CompanyListReq;
import com.zg.scf.domain.vo.CompanyVo;
import com.zg.scf.service.CompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>Description: </p>
 *
 * @author zhanfeng.liang
 * @since 2025/5/22 10:54
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/scf/company")
@Slf4j
@Api(tags = "公司信息")
public class CompanyController {


    private final CompanyService companyService;

    private final CompanyConvert companyConvert;

    private final CompanyDao companyDao;


//    @PostMapping("/page")
//    @ApiOperation(value = "分页")
//    public R<Page<CompanyVo>> page(@RequestBody CompanyPageReq pageReq) {
//        Page<CompanyVo> page = CompanyService.page(pageReq,CompanyVo.class);
//        return R.success(page);
//    }

    @PostMapping("/list")
    @ApiOperation(value = "查询list")
    public R<List<Company>> list(@RequestBody @Valid CompanyListReq req) {
        List<Company> list = companyDao.list(
                new LambdaQueryWrapper<Company>()
                        .eq(StrUtil.isNotBlank(req.getCompanyType()), Company::getCompanyType, req.getCompanyType())
        );
        return R.success(list);
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增")
    public R add(@RequestBody @Valid CompanyAddReq addReq) {
        companyService.add(addReq);
        return R.success();
    }

    @PostMapping("/addApply")
    @ApiOperation(value = "新增待审核")
    public R addApply(@RequestBody @Valid CompanyAddReq addReq) {
        companyService.addApply(addReq);
        return R.success();
    }

    @GetMapping("/get")
    @ApiOperation(value = "查询")
    public R<CompanyVo> get(@Param("id") Long id) {
        Company company=companyService.getCompany(id);
        return R.success(companyConvert.toVo(company));
    }

    @GetMapping("/getApply")
    @ApiOperation(value = "查询")
    public R<CompanyVo> getApply(@Param("id") Long id) {
        Company company=companyService.getCompanyApply(id);
        return R.success(companyConvert.toVo(company));
    }

//    @PostMapping("/edit")
//    @ApiOperation(value = "修改")
//    public R edit(@RequestBody @Valid CompanyEditReq editReq) {
//        CompanyService.edit(editReq);
//        return R.success();
//    }
//
//    @PostMapping("/editState")
//    @ApiOperation(value = "修改状态")
//    public R editState(@RequestBody @Valid StateReq editReq) {
//        CompanyService.editState(editReq);
//        return R.success();
//    }
//
//    @PostMapping("/remove")
//    @ApiOperation(value = "删除")
//    public R remove(@RequestBody List<Long> ids) {
//        CompanyService.remove(ids);
//        return R.success();
//    }
//
//    @GetMapping("/listByProductType")
//    @ApiOperation(value = "获取产品类型的授信")
//    public R<List<CompanyVo>> listByProductType(@Param("id") Long id) {
//        List<Company> list=CompanyService.listByProductType(id);
//        return R.success(CompanyConvert.toVoList(list));
//    }
}
